package classes.io;

import org.junit.Test;

import java.io.*;

public class BufferedInputOutputStream {
    @Test
    public void test() {
        BufferedInputStream bufferedInputStream = null;
        BufferedOutputStream bufferedOutputStream = null;

        try {
            bufferedInputStream = new BufferedInputStream(new FileInputStream("./src/classes/io/book.pdf"));
            bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("./src/classes/io/book3.pdf"));
            byte[] buff = new byte[1024];
            while (bufferedInputStream.read(buff) != -1) {
                bufferedOutputStream.write(buff);
                bufferedOutputStream.flush();
            }


        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (bufferedInputStream != null) {
                try {
                    bufferedInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (bufferedOutputStream != null) {
                try {
                    bufferedOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
